package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.AlarmDto;
import com.hualude.roadsign.dto.AlarmPushDto;
import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.model.AlarmEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by xu_jiaHui on 2017/10/13.
 */
public interface AlarmRepository extends CrudRepository<AlarmEntity,Integer> {

    /**
     * @Description: 获取报警器用于DT展示
     * @author xu_jiaHui
     * @date 2017/10/13 14:28
     */
    public List<AlarmDto> getAlarm4DT(DTRequestDto dtRequestDto, Integer orgId, Integer actorId, Integer deviceType)throws Exception;

    public Integer getAlarmCount4DT(Integer orgId, Integer actorId, Integer deviceType)throws Exception;


    public List<AlarmDto> getAlarmBySearch4DT(DTRequestDto dtRequestDto,String orgId,String deviceId,String createTime,Integer deviceType)throws Exception;


    public Integer getAlarmCountBySearch4DT(DTRequestDto dtRequestDto,String orgId,String deviceId,String createTime,Integer deviceType)throws Exception;

    @Modifying
    @Query(value = "update AlarmEntity set deviceId=?1, deviceState=?2,deviceModel=?3,deviceManufacturer=?4,deviceAddress=?5,updateTime=?6,cycleTime=?8,specialPoint=?9,deviceOrgId=?10 where alarmId=?7")
    public Integer updateAlarm(String deviceId, Integer deviceState, String deviceModel, String deviceManufacturer, String deviceAddress, String updateTime, Integer alarmId,Integer cycleTime,String specialPoint,Integer deviceOrgId);

    @Modifying
    @Query(value = "delete from AlarmEntity where alarmId=?1")
    public Integer deleteAlarmById(Integer alarmId)throws Exception;

    public List<AlarmDto> getAlarmPath (String deviceId) throws Exception;

    public List<AlarmDto> getAlarmList(Integer orgId) throws Exception;

    @Modifying
    public Integer updapteAlarmPath(Integer deviceType,Integer devicePathId,String deviceId)throws Exception;

    @Modifying
    @Query(value = "update AlarmEntity set deviceType=?2,devicePathId=?1 where alarmId=?3")
    public Integer boundingDeviceId(Integer deviceId, Integer deviceType, Integer alarmId)throws Exception;

    @Modifying
    @Query(value = "update AlarmEntity set deviceType=?1,devicePathId=?2,deviceAddress=?3 where deviceId=?4")
    public Integer bindingDevice(int DeviceType, Integer DevicePathId, String position,String deviceId)throws Exception;

    @Modifying
    @Query(value = "update AlarmEntity set deviceType=-1,deviceAddress='未知地点',devicePathId=null where deviceId=?1")
    public Integer unbindingDevice(String deviceId) throws Exception;

    @Query(value = "select deviceId from AlarmEntity where deviceModel=?1")
    public List<String> getDeviceIdByModel(String ruleModelId)throws Exception;

    @Modifying
    @Query(value = "update AlarmEntity set cycleTime=?2 where deviceId=?1")
    public Integer setCycleTime(String deviceId, Integer cycleTime)throws Exception;


}
